/*    */ package com.zimbra.qa.unittest;
/*    */ 
/*    */ import com.zimbra.client.ZInvite;
/*    */ import com.zimbra.client.ZInvite.ZComponent;
/*    */ import com.zimbra.client.ZInvite.ZOrganizer;
/*    */ import com.zimbra.client.ZInvite.ZStatus;
/*    */ import com.zimbra.client.ZMailbox;
/*    */ import com.zimbra.client.ZMailbox.ZAppointmentResult;
/*    */ import com.zimbra.client.ZMailbox.ZOutgoingMessage;
/*    */ import com.zimbra.client.ZSearchParams;
/*    */ import com.zimbra.client.ZSearchResult;
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.soap.type.SearchSortBy;
/*    */ import java.util.ArrayList;
/*    */ import java.util.List;
/*    */ import org.junit.AfterClass;
/*    */ import org.junit.Assert;
/*    */ import org.junit.BeforeClass;
/*    */ import org.junit.Test;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class TestSearchTask
/*    */ {
/* 41 */   private static String USER_NAME = "user1";
/*    */   private static ZMailbox mbox;
/* 43 */   private static ArrayList<String> ids = new ArrayList();
/*    */   private static final int numTasks = 60;
/*    */   private static final int limit = 50;
/*    */   
/*    */   @BeforeClass
/*    */   public static void populate() throws ServiceException {
/* 49 */     mbox = TestUtil.getZMailbox(USER_NAME);
/* 50 */     for (int i = 0; i < 60; i++) {
/* 51 */       ZMailbox.ZOutgoingMessage msg = TestUtil.getOutgoingMessage(USER_NAME, null, String.format("task body %d", new Object[] { Integer.valueOf(i) }), null);
/* 52 */       ZInvite inv = new ZInvite();
/* 53 */       ZInvite.ZComponent comp = new ZInvite.ZComponent();
/* 54 */       comp.setIsAllDay(true);
/* 55 */       comp.setStatus(ZInvite.ZStatus.NEED);
/* 56 */       comp.setLocation("mount erebor");
/* 57 */       comp.setPercentCompleted("0");
/* 58 */       comp.setPriority("0");
/* 59 */       comp.setName(String.format("destroy the one ring %d", new Object[] { Integer.valueOf(i) }));
/* 60 */       comp.setOrganizer(new ZInvite.ZOrganizer(mbox.getName()));
/*    */       
/* 62 */       inv.getComponents().add(comp);
/* 63 */       ZMailbox.ZAppointmentResult resp = mbox.createTask("15", null, msg, inv, null);
/* 64 */       ids.add(resp.getInviteId());
/*    */     }
/*    */   }
/*    */   
/*    */   @Test
/*    */   public void testTaskSearch() throws Exception
/*    */   {
/* 71 */     int offset = 0;
/*    */     boolean hasMore;
/*    */     do {
/* 74 */       ZSearchParams params = new ZSearchParams("in:tasks");
/* 75 */       params.setTypes("task");
/* 76 */       params.setOffset(offset);
/* 77 */       params.setLimit(50);
/* 78 */       params.setSortBy(SearchSortBy.taskDueAsc);
/* 79 */       ZSearchResult resp = mbox.search(params);
/* 80 */       int numResults = resp.getHits().size();
/* 81 */       hasMore = resp.hasMore();
/* 82 */       Assert.assertEquals(Math.min(50, 60 - offset), numResults);
/* 83 */       offset += numResults;
/*    */     }
/* 85 */     while (hasMore == true);
/*    */   }
/*    */   
/*    */   @AfterClass
/*    */   public static void destroy() throws ServiceException {
/* 90 */     for (String id : ids) {
/* 91 */       mbox.cancelTask(id, "0", null, null, null, null);
/*    */     }
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/TestSearchTask.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */